package edu.unlv.cs.ladders.notification;

import java.util.Collection;

import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.util.Assert;

import edu.unlv.cs.ladders.entities.Participant;
import edu.unlv.cs.ladders.entities.Team;

@RooJavaBean
public class NotificationImpl implements Notification {
	private SimpleMailMessage message;
	private MailSender sender;

	public void notifyTeams(Team... teams) {
		for(Team team : teams){
			notifyParticipants(team.getMembers());
		}
	}

	public void notifyParticipant(Participant participant) {
		Assert.notNull(participant);
		message.setTo(participant.getEmailAddress());
		sender.send(message);
	}

	public void notifyParticipants(Collection<Participant> participants) {
		for(Participant participant : participants){
			notifyParticipant(participant);
		}
	}
	
}
